#!/usr/bin/python3
import json
import time
"""
生成阅读3.0全角替换成半角替换规则
"""
#with open("exportReplaceRule.json", "r", encoding='utf8') as f:
    #jsonData = f.read()
#obj = json.loads(jsonData)
obj = []
x = 0x0020
index = -95
while x <= 0x7e:
    i = {}
    i['group'] = "替换,前置"
    i['id'] = int(round(time.time() * 1000))
    i['isEnabled'] = True
    i['isRegex'] = False
    i['name'] = "替换全角"+chr(x)
    i['order'] = index
    index += 1
    if x == 0x0020: # 除了空格其他的全角半角的公式为: 半角 = 全角 - 0xfee0
        i['pattern'] = chr(0x3000)
    else:
        i['pattern'] = chr(x+0xfee0)
    i['replacement'] = chr(x)
    i['scope'] = ""
    time.sleep(0.001)
    obj.append(i)
    x += 1

with open("exportReplaceRule_.json", "w", encoding='utf8') as f:
    json.dump(obj, f, indent=2, ensure_ascii=False)